/**
 * @Author 天下无敌
 * @Date 
 * @AIDE AIDE+ 
 */
package com.ecs.core.system.abs;
import com.artemis.BaseEntitySystem;
import com.artemis.Aspect;
import com.artemis.utils.IntBag;
import com.badlogic.gdx.utils.Array;

public abstract class BaseCullingSystem extends BaseEntitySystem
{
	protected Array<Integer> activesEntityIds = new Array<>();
	protected int updateCount = 0;
	
	public BaseCullingSystem(){}
	public BaseCullingSystem(Aspect.Builder asp){
		super(asp);
	}

	@Override
	protected void begin()
	{	
		IntBag actives = subscription.getEntities();
		int[] ids = actives.getData();
		for(int i = 0;i < actives.size();i++){
			if(world.getEntity(ids[i]).isActive() && isCulling(ids[i])){
				activesEntityIds.add(ids[i]);
			}
		}
		
		optimizedBubbleSort();
	}
	
	
	@Override
	protected void processSystem()
	{
		for(int i = 0;i < activesEntityIds.size;i++){
			process(activesEntityIds.get(i));
		}
	}

	@Override
	protected void end()
	{
		super.end();
		updateCount = activesEntityIds.size;
		activesEntityIds.clear();
	}

	
	protected abstract void process(int entityId);
	protected abstract boolean isCulling(int entityId);

    // 可以保留原有排序实现或改进
    protected void optimizedBubbleSort() {
        // 实现你的排序逻辑
    }
	
	public int getCounts(){
		return updateCount;
	}
	
}
